// src/utils/registerSW.ts
import { Workbox } from 'workbox-window'

export function registerSW() {
  if ('serviceWorker' in navigator) {
    const wb = new Workbox('/sw.js')
    
    wb.addEventListener('controlling', () => {
      window.location.reload() // 当新Service Worker接管时刷新页面
    })
    
    wb.register()
  }
}